#
# @lc app=leetcode.cn id=594 lang=python
#
# [594] 最长和谐子序列
#

# @lc code=start
class Solution(object):
    def findLHS(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        nums.sort()
        res = 0
        start = 0
        for i in range(1, len(nums)):
            while nums[i]-nums[start]>1:
                start+=1
            if nums[i]-nums[start] == 1:
                res = max(res, i-start+1)
        return res
# @lc code=end

